import Vue from "vue";
import Router from "vue-router";
import Home from "@/views/Home.vue";
import Login from "@/views/Login.vue";
import store from "@/store";

Vue.use(Router);

const routes = [
  {
    path: "/Home",
    name: "Home",
    component: Home,
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
  },

];

const router = new Router({ routes });

export default router;

router.beforeEach((to, from, next) => {
  const authToken = store.state.authToken;
  if (!authToken && to.name !== "Login") {
    next({ name: "Login" });
  } else {
    next();
  }
});
